package whf.framework.security.dao;

import java.util.List;

import whf.framework.dao.hibernate.HibernateHelper;
import whf.framework.dao.param.IParam;
import whf.framework.dao.param.LongParam;
import whf.framework.exception.FindException;
import whf.framework.security.entity.Group;
import whf.framework.security.entity.Role;
import whf.framework.security.entity.User;
import whf.framework.util.Utils;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-05-31
 */
public class GroupDAOImp extends whf.framework.dao.DAOImp<Group> implements GroupDAO {
	/* (non-Javadoc)
	 * @see whf.framework.security.dao.GroupDAO#findByUser(whf.framework.security.entity.User)
	 */
	public List<Group> findByUser(User user) throws FindException{
		List<IParam> params = Utils.newArrayList();
		params.add(new LongParam("user_id", user == null? 0:user.getId()));
		return HibernateHelper.getNamedQueryResult("find-group-by-user",params);
	}

	/* (non-Javadoc)
	 * @see whf.framework.security.dao.GroupDAO#findByRole(whf.framework.security.entity.Role)
	 */
	public List<Group> findByRole(Role role) throws FindException {
		List<IParam> params = Utils.newArrayList();
		params.add(new LongParam("role_id", role == null? 0:role.getId()));
		return HibernateHelper.getNamedQueryResult("find-group-by-role",params);
	}
	
	
} 